package com.ghck.server.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ghck.server.model.Knowledge;
import com.ghck.server.model.request.KnowledgeReq;
import com.ghck.server.model.response.KnowledgeRes;

public interface KnowledgeMapper {

	@Select("select * from t_knowledge order by publish_time desc limit #{start},#{limit}")
	public List<KnowledgeRes> list(KnowledgeReq knowledgeReq);
	
	@Select("select * from t_knowledge where id = #{id}")
	public KnowledgeRes detail(Knowledge knowledge);
	
	@Insert("insert into t_knowledge(title,excerpt,pic_url,content,read_count,publish_time) "
			+ " values (#{title},#{excerpt},#{picUrl},#{content},#{readCount},#{publishTime})")
	@Options(useGeneratedKeys=true)
	public Integer add(Knowledge knowledge);
	
	@Delete("delete from t_knowledge where id = #{id}")
	public void delete(Knowledge knowledge);
	
	@Update("update t_knowledge set title = #{title},excerpt = #{excerpt},content = #{content},"
			+ " read_count = #{readCount},publish_time = #{publishTime} where id = #{id}")
	public void update(Knowledge knowledge);
}
